package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NurLeUpdateVo;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController extends BaseController{
    @Autowired
    private NursingLevelService nursingLevelService;
    @GetMapping("/listAll")
    public ResponseResult<List<NursingLevelVo>> listAll(){
        List<NursingLevelVo> nursingLevelVoList = nursingLevelService.listAll();
        return success(nursingLevelVoList);
    }

    @PostMapping("/insert")
    public ResponseResult addLevel(@RequestBody NursingLevel nursingLevel){
        nursingLevelService.addLevel(nursingLevel);
        return success();
    }


    /**
     * 3.7 启用禁用
     * */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult disableById(@PathVariable("id") Long id,
                                      @PathVariable("status") Integer status) {
        nursingLevelService.disableById(id, status);
        return success();
    }
    /**
     * 3.6 删除
     * */
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteById(@PathVariable("id") Long id) {
        nursingLevelService.deleteById(id);
        return success();}


        @GetMapping("/listByPage")
    public ResponseResult<PageResponse> listPage(
            @RequestParam(value ="name" ,required = false) String name,
            @RequestParam(value ="pageNum",  required = false) Integer pageNum,
            @RequestParam(value ="pageSize", required = false)Integer pageSize,
            @RequestParam(value ="status",required = false) Integer status){
        PageResponse<NursingLevelVo> PageNursingLevel = nursingLevelService.listPage(name, pageNum, pageSize, status);
        return success(PageNursingLevel);
    }
    /**
     *3.5 修改
     * */
    @PutMapping("/update")
    public ResponseResult updateById(@RequestBody NurLeUpdateVo nursingLevel) {
        nursingLevelService.updateById(nursingLevel);
        return success();
    }

    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> getById(@PathVariable("id") Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }
}
